package com.cskaoyan.service.user;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cskaoyan.bean.bo.user.AdminUserListBO;
import com.cskaoyan.bean.po.user.AdminCollectPO;
import com.cskaoyan.bean.po.user.AdminUserAddressPO;
import com.cskaoyan.bean.vo.user.AdminCollectVO;
import com.cskaoyan.bean.vo.user.AdminUserAddressVO;
import com.cskaoyan.mapper.user.AdminCollectMapper;
import com.cskaoyan.util.beanutils.BeanUtil;
import com.cskaoyan.util.common.StringUtils;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.Data;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author: 冯子靖
 * @Description:
 * @Date: 2022/7/18 16:26
 */
@Service
@Data
public class AdminCollectServiceImpl implements AdminCollectService {
    private Integer limit;

    private Integer page;

    private Integer pages;

    private Integer total;

    private List<AdminCollectPO> list;
    @Autowired
    AdminCollectMapper adminCollectMapper;
    @Override
    public AdminCollectVO printAdminCollectList(AdminUserListBO adminUserListBO) {
        page = adminUserListBO.getPage();
        limit = adminUserListBO.getLimit();

        Integer userId = adminUserListBO.getUserId();
        Integer valueId = adminUserListBO.getValueId();

        PageHelper.startPage(page, limit);
        if (userId == null && valueId == null) {
            list = adminCollectMapper.selectList(null);

        } else {
            QueryWrapper<AdminCollectPO> adminUserListPOQueryWrapper = new QueryWrapper<>();

            adminUserListPOQueryWrapper.eq(!(userId == null), "id", userId);
            adminUserListPOQueryWrapper.like(!(valueId == null), "valueId", valueId);
            list = adminCollectMapper.selectList(adminUserListPOQueryWrapper);
        }

        PageInfo<AdminCollectPO> adminUserAddressPOPageInfo = new PageInfo<>(list);
        total = (int) adminUserAddressPOPageInfo.getTotal();
        pages = adminUserAddressPOPageInfo.getPages();
        AdminCollectVO adminCollectVO = new AdminCollectVO();
        BeanUtil.copyBean(this, adminCollectVO);
        return adminCollectVO;
    }
}
